package com.test.pdproject.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class CustomExceptionResolver implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
			Object handler, Exception ex) {
		CustomException customException = null;
		if(ex instanceof CustomException){
			customException = (CustomException) ex;
		}else{
			customException = new CustomException("未知错误！");
		}
		// 异常处理
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("error");  //页面名称
		modelAndView.addObject("error_message", customException.getMessage());
		return modelAndView;
	}
	//异常信息

}
